﻿using System;
using System.Data;
using System.Windows.Forms;
using FoundationClass;
using FoundationClass.Entity;

namespace P2MARY_INTERNET.Controls
{
    public partial class PaymentHistoryForm : UserControl
    {
        public PaymentHistoryForm()
        {
            InitializeComponent();
        }

        private void SetupGrid()
        {
            try
            {
                var dt = new DataTable();
                dt.Columns.Add("serviceid", typeof(string));
                dt.Columns.Add("comNo", typeof(string));
                dt.Columns.Add("type", typeof(string));
                dt.Columns.Add("promotion", typeof(string));
                dt.Columns.Add("start", typeof(string));
                dt.Columns.Add("finish", typeof(string));
                dt.Columns.Add("amount", typeof(string));
                dt.Columns.Add("totalamount", typeof(string));
                dt.Columns.Add("paidtime", typeof(string));
                dt.Columns.Add("employee", typeof(string));


                var list = MasterDataHandler.GetAllServiceRecordsPaid();
                foreach (ServiceRecord sr in list)
                {
                    string type = "Internet";
                    if (sr.Computer.ComputerType == 'G')
                        type = "Games";

                    dt.Rows.Add(sr.Id, sr.Computer.Id.ToString(), type, sr.Promotion.Name , sr.RecordStart.ToLongTimeString(), sr.RecordEnd.HasValue ? sr.RecordEnd.Value.ToLongTimeString() : string.Empty, sr.RecordAmount, sr.Payment.TotalAmount, sr.Payment.PaidTime.ToString(), sr.Payment.Employee.Username);
                }
                grdPaymentHistory.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void Setup()
        {
            SetupGrid();
        }

        private void PaymentHistoryForm_Load(object sender, EventArgs e)
        {
            SetupGrid();
        }

    }
}
